import Vue from 'vue'
import Vuex from 'vuex'
import MyStorage from './common/js/cache'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    searchValue: MyStorage.getItem('searchValue') || '',
    userInfo: MyStorage.getItem('userInfo') || '',
    curDataSet: MyStorage.getItem('curDataSet') || '',
    curProject: MyStorage.getItem('curProject') || '',
    curTask: MyStorage.getItem('curTask') || '',
    curTaskConfig: MyStorage.getItem('curTaskConfig') || '',
    curPublicProject: MyStorage.getItem('curPublicProject') || '',
    taskFromHome: MyStorage.getItem('taskFromHome') || '',
    taskDataSet: MyStorage.getItem('taskDataSet') || '',
    curEditFile: MyStorage.getItem('curEditFile') || '',
    curFilePath: MyStorage.getItem('curFilePath') || '',
    jobCodeNo: MyStorage.getItem('jobCodeNo') || ''
  },
  mutations: {
    'SET_SEARCH_VALUE': function (state, searchValue) {
      MyStorage.setItem('searchValue', searchValue)
      state.searchValue = searchValue
    },
    'SET_USERINFO': function (state, userInfo) {
      MyStorage.setItem('userInfo', userInfo)
      state.userInfo = userInfo
    },
    'SET_CUR_DATASET': function (state, curDataSet) {
      MyStorage.setItem('curDataSet', curDataSet)
      state.curDataSet = curDataSet
    },
    'SET_CUR_PROJECT': function (state, curProject) {
      MyStorage.setItem('curProject', curProject)
      state.curProject = curProject
    },
    'SET_CUR_TASK': function (state, curTask) {
      MyStorage.setItem('curTask', curTask)
      state.curTask = curTask
    },
    'SET_CUR_TASK_CONFIG': function (state, curTaskConfig) {
      MyStorage.setItem('curTaskConfig', curTaskConfig)
      state.curTaskConfig = curTaskConfig
    },
    'LOG_OUT': function (state) {
      MyStorage.clear()
      state.userInfo = ''
    },
    'SET_CUR_PUBULICPROJECT': function (state, curPublicProject) {
      MyStorage.setItem('curPublicProject', curPublicProject)
      state.curPublicProject = curPublicProject
    },
    'SET_TASK_FROM_HOME': function (state, taskFromHome) {
      MyStorage.setItem('taskFromHome', taskFromHome)
      state.taskFromHome = taskFromHome
    },
    'Set_Task_Data_Set': function (state, taskDataSet) {
      MyStorage.setItem('taskDataSet', taskDataSet)
      state.taskDataSet = taskDataSet
    },
    'SET_CUR_EDIT_FILE': function (state, curEditFile) {
      MyStorage.setItem('curEditFile', curEditFile)
      state.curEditFile = curEditFile
    },
    'SET_CUR_FILEPATH': function (state, curFilePath) {
      MyStorage.setItem('curFilePath', curFilePath)
      state.curFilePath = curFilePath
    },
    'SET_JOB_CODENO': function (state, jobCodeNo) {
      MyStorage.setItem('jobCodeNo', jobCodeNo)
      state.jobCodeNo = jobCodeNo
    }
  },
  getters: {
    searchValue: state => {
      return state.searchValue
    },
    userInfo: state => {
      return state.userInfo
    },
    curDataSet: state => {
      return state.curDataSet
    },
    curProject: state => {
      return state.curProject
    },
    curTask: state => {
      return state.curTask
    },
    curTaskConfig: state => {
      return state.curTaskConfig
    },
    curPublicProject: state => {
      return state.curPublicProject
    },
    taskFromHome: state => {
      return state.taskFromHome
    },
    taskDataSet: state => {
      return state.taskDataSet
    },
    curEditFile: state => {
      return state.curEditFile
    },
    curFilePath: state => {
      return state.curFilePath
    },
    jobCodeNo: state => {
      return state.jobCodeNo
    }
  }
})
